package middleware

import (
	"blog_api/db"
	"fmt"
	"github.com/gin-gonic/gin"
	"net/http"
)

/**
 * AdminMiddleware
 * @Description: 后台接口中间件
 * @Author: Jazk-Z
 * @param c
 */
func AdminMiddleware(c *gin.Context) {
	token := c.GetHeader("Authorization")
	auid, _ := db.RedisGetInt(token)
	fmt.Println("====auid====", auid)
	if auid == 0 {
		c.Set("auid", auid)
		c.AbortWithStatusJSON(http.StatusOK, gin.H{
			"code":    50014,
			"message": "token已失效，重新登录",
			"data":    "",
		})
		return
	}
}
